<template>
  <div class="user">
    <div class="pageHeader">
      个人中心
      <!-- <img src="@/static/images/arrow-left.png" alt="" @click="back"> -->
    </div>

    <div class="userInfo">
      <!--  :style="'background:url('+storeInfo.pic+') no-repeat center'" -->
      <div class="userBG"></div>

      <div class="userContent">
        <div class="userPic">
          <img v-if="userInfo.avatar" :src="userInfo.avatar" alt="">
          <img v-else :src="avatar_default" alt="">
        </div>

        <div class="userShow">
          <p class="userName">{{ userInfo.nickname?userInfo.nickname:"用户_"+userInfo.account }}</p>
          <p class="userElse"></p>
          <p class="userID">小白球号：{{ userInfo.account }}</p>
        </div>

        <div class="userEdit" @click="$router.push(routerUrl+'/userEdit')">
          <van-icon name="setting-o" size="18" />
        </div>
      </div>
    </div>

    <div class="userOrder">
      <div class="orderTop">
        <h1>我的订单</h1>
        <router-link :to="{path:routerUrl+'/orderlist/-1'}">
          查看全部订单<van-icon name="arrow" color="#cccccc" size="14" />
        </router-link>
      </div>

      <ul class="orderStatus">
        <li>
          <router-link :to="routerUrl+'/orderlist/0'">
            <van-icon name="todo-list-o" color="#1989fa" size="32" :badge="unpaid" />
            <p>待付款</p>
          </router-link>
        </li>

        <li>
          <router-link :to="routerUrl+'/orderlist/1'">
            <van-icon name="send-gift-o" color="#1989fa" size="32"  />
            <p>已付款</p>
          </router-link>
        </li>

        <li>
          <router-link :to="routerUrl+'/orderlist/2'">
            <van-icon name="refund-o" color="#1989fa" size="32"  />
            <p>退款</p>
          </router-link>
        </li>
      </ul>

      <!-- <div class="orderShow">
        <div class="showTop">
          <div class="showStatus">
            待付款
          </div>

          <div class="showDate">
            预计时间：4月5日
          </div>
        </div>

        <div class="showTel">
          <p>133151684684</p>
          <p>133151684684</p>
          <span>(2人)</span>
        </div>

        <div class="showGround">
          <p class="ground">
            XXXXXX球场 / 1月7日 07:00
          </p>

          <p class="showTotal">
            ￥1600
          </p>
        </div>
      </div> -->
    </div>

    <!-- <div class="Vip">
      <span>我的会籍</span>
      <p>认证我的会籍</p>
    </div> -->

    <div class="ticket" @click="$router.push(routerUrl+'/couponList')">
      <span>红包卡卷</span>
      <p>{{couponNum}}张</p>
    </div>

    <div class="outLogin" @click="outLogin" >退出登入</div>
  </div>
</template>

<style scoped>
  .userEdit{
    padding: 50px 20px 0 20px;
  }

  .outLogin{
    width: calc(100% - 50px);
    height: 80px;
    background-color: #ee0a24;
    text-align: center;
    font-size: 28px;
    color: #ffffff;
    line-height: 80px;
    margin: 40px auto 0;
    border-radius: 50px;
  }

  .user {
    min-height: calc(100vh - 120px) ;
    background: #f2f3f5;
  }

  .userInfo {
    position: relative;
  }

  .userInfo .userBG {
    height: 200px;
    background-size: 100% 335px;
    filter: blur(20px);
  }

  .userInfo .userContent {
    position: absolute;
    bottom: -20px;
    left: 50%;
    display: flex;
    height: 200px;
    background: #ffffff;
    width: calc(100% - 40px);
    transform: translateX(-50%);
    border: 1px solid #f5f5f5;
  }

  .userInfo .userContent .userPic , .userInfo .userContent .userPic img {
    width: 96px;
    height: 96px;
  }
  
  .userInfo .userContent .userPic {
    padding: 40px 20px 0 40px;
  }

  .userInfo .userContent .userShow {
    padding-top: 50px;
    flex: 1;
  }

  .userInfo .userContent .userShow p {
    text-align: left;
  }

  .userInfo .userContent .userShow .userName {
    font-size: 32px;
    font-weight: 700;
  }

  .userInfo .userContent .userShow .userElse {
    margin: 20px 0 16px;
  }

  .userOrder {
    margin: 40px 20px 0;
    padding-bottom: 20px;
    background: #ffffff;
  }

  .userOrder .orderTop {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #cccccc;
  }

  .userOrder .orderTop a {
    display: flex;
    align-items: center;
    color: #cccccc;
  }

  .userOrder .orderStatus {
    display: flex;
    padding: 40px 0 20px;
  }

  .userOrder .orderStatus li {
    width: 33%;
    text-align: center;
  }
  
  .userOrder .orderStatus li p {
    margin: 6px;
  }

  .userOrder .orderShow {
    margin: 20px 20px 0;
    padding: 20px;
    background: #f5f5f5;
  }

  .userOrder .orderShow .showTop , .userOrder .orderShow .showTel , .userOrder .orderShow .showGround {
    display: flex;
    justify-content: space-between;
  }

  .userOrder .orderShow .showTop {
    margin-bottom: 30px;
  }

  .userOrder .orderShow .showTop .showStatus {
    color: #1989fa;
  }

  .userOrder .orderShow .showTel {
    justify-content: flex-start;
    margin-bottom: 20px;
  }

  .userOrder .orderShow .showTel p {
    position: relative;
    padding-right: 20px;
  }

  .userOrder .orderShow .showTel p::after{
    position: absolute;
    right: 10px;
    content: ',';
    width: 10px;
    height: 10px;
  }

  .userOrder .orderShow .showGround .ground {
    color: #cccccc;
  }

  .userOrder .orderShow .showGround .showTotal {
    color: orangered;
  }

  .Vip , .ticket {
    display: flex;
    justify-content: space-between;
    background: #ffffff;
    margin: 20px 20px 0;
    padding: 0 20px;
    line-height: 80px;
  }

  .Vip span , .ticket span {
    font-size: 30px;
  }

  .Vip p , .ticket p {
    color: #1989fa;
  }
</style>

<script>
import Vue from 'vue';
import { Icon } from 'vant';
import config from 'api/config.js'
import api from 'api'
import avatar_default from 'static/images/avatar_default.png'

Vue.use(Icon);
export default {
  data() {
    return {
      avatar_default,
      routerUrl:config.routerUrl,
      user:{
        name: '小白球',
        else: '2333',
        id: 1
      },
      unpaid:0,
      couponNum:0
    }
  },
  activated() {
    this.getCoupons()
  },
  methods: {
    back(){
      this.$router.go(-1);//返回上一层
    },
    getCoupons(){
      api.get("/order/getCoupons").then(e=>{
        this.couponNum = e.data.length
        this.getUnpaid()
      })
    },
    getUnpaid(){
      api.get("/order/countUnpaidOrder").then(e=>{
        this.unpaid = e.data.unpaid_order_count
      })
    },
    outLogin(){
      this.$store.commit("user/outLogin")
    }
  },
  computed:{
    userInfo(){
      let member = this.$store.state.user.userInfo?this.$store.state.user.userInfo.member:{}
      return member
    },
    storeInfo(){
      return this.$store.state.common.storeData
    }
  }
}
</script>